import { createWebHistory, createRouter } from "vue-router";
import { getToken } from '@/utils/auth';
const routes = [
    {
        path: '/login',
        name: "login",
        component: () => import('@/views/main/login.vue')
    },
    {
        path: '/register',
        name: "register",
        component: () => import('@/views/main/register.vue')
    },
    // {
    //     path: '/',
    //     name: "index",
    //     component: () => import('@/views/main/layout/index.vue'),
    //     children: [
    //         {
    //             path: 'system',
    //             name: "系统管理",
    //             children: [
    //                 {
    //                     path: 'userManage',
    //                     name: "用户管理",
    //                     component: () => import('@/views/main/system/userManage.vue'),
    //                 },
    //             ]
    //         },

    //         {
    //             path: 'main',
    //             name: "mainBlog",
    //             component: () => import('@/views/main/blog/main.vue'),
    //         },
    //         {
    //             path: 'premium',
    //             name: "premiumBlog",
    //             component: () => import('@/views/main/blog/premium.vue'),
    //         },
    //         {
    //             path: 'all',
    //             name: "allBlog",
    //             component: () => import('@/views/main/blog/all.vue'),
    //         },
    //         {
    //             path: 'follow',
    //             name: "followBlog",
    //             component: () => import('@/views/main/blog/follow.vue'),
    //         },
    //         {
    //             path: 'about',
    //             name: "about",
    //             component: () => import('@/views/main/about.vue'),
    //         },
    //         {
    //             path: 'myBlog',
    //             name: "myBlog",
    //             component: () => import('@/views/main/user/myBlog.vue'),
    //         }, {
    //             path: 'chat',
    //             name: "userChat",
    //             component: () => import('@/views/main/user/chat.vue'),
    //         }
    //     ]
    // },

]
import menus from './menu'
const mainMenu = {
    path: '/',
    name: "index",
    component: () => import('@/views/main/layout/index.vue'),
    children: menus
}
routes.push(mainMenu)



const router = createRouter({
    history: createWebHistory(),
    routes
})

router.beforeEach((to, from, next) => {
    if (to.path != '/login' && !getToken()) {
        next('/login') // 如果未登录，跳转到登录页
    } else {
        next() // 否则放行
    }
})

export default router
